import Particle from './particle';

const FRACTION=(num,mul=1)=>{
    let n=num*mul;
    return n-Math.floor(n);
};

export default class ParticleSquare extends Particle{
    constructor(values={}){
        super(values);
        this.props.add({
            widthStart:values.widthStart||0.5,
            heightStart:values.heightStart||0.2,
            widthEnd:values.widthEnd||1,
            heightEnd:values.heightEnd||0.5,
        });
    }
    initPropCallback(){
        super.initPropCallback();
        this.props.onMultiKeyChange(()=>{
            this.wScl=this.props.widthEnd.value/this.props.widthStart.value;
        },'widthStart','widthEnd');
        this.props.onMultiKeyChange(()=>{
            this.hScl=this.props.heightEnd.value/this.props.heightStart.value;
        },'heightStart','heightEnd');
    }
    initVariable(){
        super.initVariable();
        this.wScl=this.props.widthEnd.value/this.props.widthStart.value;
        this.hScl=this.props.heightEnd.value/this.props.heightStart.value;
    }
    setStartVertSpeed(rand,i,t){
        this.verts[i]=-this.props.widthStart.value+this.props.widthStart.value*2*FRACTION(rand,1e4);
        this.verts[i+2]=-this.props.heightStart.value+this.props.heightStart.value*2*FRACTION(rand,1e5);

        this.speeds[i]=this.verts[i]*this.wScl-this.verts[i];
        this.speeds[i+1]=this.props.speedMin.value+(this.props.speedMax.value-this.props.speedMin.value)*FRACTION(rand,1e6);
        this.speeds[i+2]=this.verts[i+2]*this.hScl-this.verts[i+2];
    }
}